<?php

namespace app\index\validate;

use think\Validate;

class JfUser extends Validate
{
  protected $rule = [
    'phone'=>'require|max:11|checkPhone',
    'verifyCode'=>'require|max:4',
  ];
  protected $message = [
    'phone.require'=>'手机号码不能为空!',
    'phone.max'=>'手机号码过长',
    'verifyCode.require'=>'验证码不能为空！',
    'verifyCode.max'=>'验证码过长',
  ];
  protected $scene = [
    'login' =>['phone', 'verifyCode'],
  ];
  public function checkPhone($value, $rules, $data=[])
  {
    if (!preg_match("/^1[34578]\d{9}$/", $value)){
      return '手机号码格式不正确！';
    }
    return true;
  }
}
